package com.micangcaihang.micang.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.micangcaihang.common.utils.ConvertUtils;
import com.micangcaihang.micang.R;
import com.micangcaihang.micang.entity.TaskPriceSurveyEntity;

import java.util.List;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/07/25
 *     update : 2017/07/25
 *     desc   : 新楼价格适配器
 *     version: 1.0
 * </pre>
 */

public class DNewTowerPriceAdapter extends BaseQuickAdapter<TaskPriceSurveyEntity.XinLou, BaseViewHolder> {

    public DNewTowerPriceAdapter(@LayoutRes int layoutResId, @Nullable List<TaskPriceSurveyEntity.XinLou> data) {
        super(layoutResId, data);
    }

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * @param helper A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    @Override
    protected void convert(BaseViewHolder helper, TaskPriceSurveyEntity.XinLou item) {
        int position = helper.getLayoutPosition();
        helper.addOnClickListener(R.id.iv_delete);
        helper.setText(R.id.et_unit_price, item.getUnit_price());
        helper.setText(R.id.et_reference_name, item.getReference_name());
        helper.setText(R.id.et_estimate_fee, item.getEstimate_fee());
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        int dp_22 = ConvertUtils.dp2px(15);
        params.setMargins(0, 0, 0, dp_22);
        helper.itemView.setLayoutParams(params);
        EditText et_unit_price = helper.getView(R.id.et_unit_price);
        et_unit_price.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                item.setUnit_price(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        EditText et_reference_name = helper.getView(R.id.et_reference_name);
        et_reference_name.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                item.setReference_name(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        EditText et_estimate_fee = helper.getView(R.id.et_estimate_fee);
        et_estimate_fee.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                item.setEstimate_fee(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}
